package com.pd;

import com.pd.pojo.PdOrder;
import com.pd.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName OrderConsumer
 * @Description:类描述
 * @Author Tedu
 * @Date 2021/6/30 9:34
 * @Version V1.0
 **/
/*
 基础配置:1依赖 2连接 3队列
 消费者从orderQueue接收订单
 调用业务代码,完成订单存储
 */
@RabbitListener(queues = "orderQueue")
@Component
public class OrderConsumer {
    @Autowired
    private OrderService orderService;
    @RabbitHandler //配合@RabbitListener指定处理消息的方法
    public void receive(PdOrder pdOrder) throws Exception {
      orderService.saveOrder(pdOrder);
        System.out.println("订单已存储,id= "+pdOrder.getOrderId());

    }

}
